package top.zz;

public class StackTest {

}

interface Satck {

	Object push(Object object);

	boolean isEmpty();

	Object pop();

}

class MyStack implements Satck {
	Object[] arrays;

	int maxSize;

	int top;

	public MyStack(int size) {
		arrays = new Object[size];
	}

	@Override
	public Object push(Object object) {

		if (isFull()) {
			System.out.println("栈已满");
		} else {
			arrays[top] = object;
			if (top < arrays.length) {
				top++;
			}
			maxSize++;
		}

		return object;
	}

	@Override
	public Object pop() {
		if (isEmpty()) {
			return null;
		} else {
			Object object = arrays[top];
			arrays[top] = null;
			top--;
			maxSize--;
			return object;
		}
	}

	@Override
	public boolean isEmpty() {
		return maxSize == 0;
	}

	public boolean isFull() {
		return maxSize == arrays.length;
	}
}

/**
 * 使用链表实现
 * 
 * @author game
 *
 */
class LinkedStack implements Satck {
	SingleLinkedList linkedList;

	public LinkedStack() {
		linkedList = new SingleLinkedList();
	}

	@Override
	public Object push(Object data) {
		return linkedList.addHead(data);
	}

	@Override
	public Object pop() {
		return linkedList.removeHead();
	}

	@Override
	public boolean isEmpty() {
		
		return linkedList.isEmpty();
	}
}